function resetCenter()
{
	document.getElementById('LienHe').style.display = "none";
	document.getElementById('GioiThieu').style.display = "none";
	document.getElementById('data').innerHTML = "";
	document.getElementById("SendPasswordForm").style.display = "none";	
	document.getElementById("regForm").style.display = "none";
	document.getElementById("ThongTinCaNhan_Member").style.display = "none";		
	document.getElementById("DanhSachSanPham_Member").style.display = "none";		
	document.getElementById("ChangePassword").style.display = "none";
	document.getElementById('ThemSanPham').style.display = "none";
}
function showLienHe()
{
	resetCenter();
	document.getElementById('LienHe').style.display = "block";
}
//Cap nhat thong tin Member
function showFormCapNhatThongTinCaNhan_member()
{
	resetCenter();
	var Username = document.getElementById('username').value;
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			document.getElementById("ThongTinCaNhan_Member").style.display = "block";
			document.getElementById("ThongTinCaNhan_Member").innerHTML=xmlhttp.responseText;
    	}
  	}
	xmlhttp.open("GET","ThongTinCaNhan_Member.php?Username="+Username+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
function CapNhatThongTin_Member()
{
	var Username = document.getElementById('username').value;
	var TenDoanhNghiep = document.getElementById('TenDoanhNghiepMember').value;
	var NhomNganh = document.getElementById('NhomNganhMember').value;	
	var SoDienThoai = document.getElementById('PhoneMember').value;
	var SoFax = document.getElementById('FaxMember').value;
	var DiaChi = document.getElementById('AddressMember').value;
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			if(xmlhttp.responseText=="1")
				document.getElementById("Result_UpdateMember").style.visibility = "visible";
    	}
  	}
	xmlhttp.open("GET","CapNhatThongTinCaNhan_Member.php?Username="+Username+"&Name="+TenDoanhNghiep+"&NhomNganh="+NhomNganh+"&Phone="+SoDienThoai+"&Fax="+SoFax+"&Address="+DiaChi+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
//Xem danh sach san pham
function showSanPham_Member(page)
{
	var username = document.getElementById('username').value;
	resetCenter();
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			document.getElementById("data").innerHTML=xmlhttp.responseText;
			var l = document.getElementsByClassName('deleteIcon').length;
			if(layout == 0)
			{
				document.getElementById('tr').style.background = "#333333";
				document.getElementById('tr').style.color = "#FFF";									
				for(i = 0; i < l; ++i)
				{
					document.getElementsByClassName('deleteIcon').item(i).style.backgroundImage = "url(images/black/delete_black.png)";
					document.getElementsByClassName('updateIcon').item(i).style.backgroundImage = "url(images/black/update_black.png)";					
				}
			}
			else if(layout == 1)
			{
				document.getElementById('tr').style.background = "#0099FF";
				document.getElementById('tr').style.color = "#FFF";													
				for(i = 0; i < l; ++i)
				{
					document.getElementsByClassName('deleteIcon').item(i).style.backgroundImage = "url(images/black/delete_black.png)";
					document.getElementsByClassName('updateIcon').item(i).style.backgroundImage = "url(images/black/update_black.png)";										
				}
			}
    	}
  	}
	xmlhttp.open("GET","sanpham_member.php?username="+username+"&page="+page+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();		
}
//Xoa san pham Member
function deleteSanPham(MaSanPham)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{		
			if(xmlhttp.responseText == 1)
			{
				document.getElementById("data").innerHTML=xmlhttp.responseText
				showSanPham_Member(0,1);
			}
    	}
  	}
	xmlhttp.open("GET","DeleteSanPham.php?MaSanPham="+MaSanPham+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
//Update thông tin sản phẩm Member
function showUpdateSanPhamForm(MaSanPham,TenSanPham,Gia,HangSanXuat,BaoHanh,URL)
{
	resetCenter();
	document.getElementById('ThemSanPham').style.display = "block";
	document.getElementById('ResultInsertSanPham').style.visibility = "hidden";
	document.getElementById('ProductName').value = TenSanPham;
	document.getElementById('ProductPrice').value = Gia;
	document.getElementById('Manufacture').value = HangSanXuat;
	document.getElementById('GuaranteePeriod').value = BaoHanh;
	document.getElementById('ProductImage').value = URL;
	document.getElementById('btnInsertSanPham').value = "Cập nhật";
	document.getElementById('btnInsertSanPham').onclick = function (){UpdateSanPham(MaSanPham)};
	document.getElementById('ResultInsertSanPham').innerHTML = "Thông tin sản phẩm đã được cập nhật";
}
function UpdateSanPham(MaSanPham)
{
	var ProductName = document.getElementById('ProductName').value;
	var ProductPrice = document.getElementById('ProductPrice').value;
	var Manufacture = document.getElementById('Manufacture').value;
	var GuaranteePeriod = document.getElementById('GuaranteePeriod').value;
	var ProductImage = document.getElementById('ProductImage').value;
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			if(xmlhttp.responseText=="1")			
				document.getElementById("ResultInsertSanPham").style.visibility = "visible";
    	}
  	}
	xmlhttp.open("GET","updateSanPham.php?MaSanPham="+MaSanPham+"&Name="+ProductName+"&Price="+ProductPrice+"&Manufacture="+Manufacture+"&Period="+GuaranteePeriod+"&Image="+ProductImage+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();	
}
//Them san pham Member
function showThemSanPhamForm()
{
	resetCenter();
	document.getElementById('ThemSanPham').style.display = "block";
	document.getElementById('btnInsertSanPham').value = "Đăng sản phẩm";
	document.getElementById('btnInsertSanPham').onclick = function (){ThemSanPham()};
	document.getElementById('ResultInsertSanPham').style.visibility = "hidden";
	document.getElementById('ProductName').value = "";
	document.getElementById('ProductPrice').value = "";
	document.getElementById('Manufacture').value = "";
	document.getElementById('GuaranteePeriod').value = "";
	document.getElementById('ProductImage').value = "";
}
function ThemSanPham()
{
	var ProductName = document.getElementById('ProductName').value;
	var ProductPrice = document.getElementById('ProductPrice').value;
	var Manufacture = document.getElementById('Manufacture').value;
	var GuaranteePeriod = document.getElementById('GuaranteePeriod').value;
	var ProductImage = document.getElementById('ProductImage').value;
	var Username = document.getElementById('username').value;
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			if(xmlhttp.responseText=="1")			
			{
				document.getElementById("ResultInsertSanPham").style.visibility = "visible";
			}
    	}
  	}
	xmlhttp.open("GET","ThemSanPham.php?Name="+ProductName+"&Price="+ProductPrice+"&Manufacture="+Manufacture+"&Period="+GuaranteePeriod+"&Image="+ProductImage+"&Username="+Username+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
//Thay doi Password Member
function showChangePasswordForm()
{
	resetCenter();	
	document.getElementById("ChangePassword").style.display = "block";
	document.getElementById("UsernameChangePassword").innerHTML = document.getElementById("username").value;
	document.getElementById('Result_ChangePassword').style.visibility = "hidden";
	document.getElementById("CurrPassChange").value = "";
	document.getElementById("NewPassChange").value = "";
	document.getElementById("ReNewPassChange").value = "";	
}
function CheckPassword()
{
	document.getElementById('Result_ChangePassword').style.visibility = "visible";
	var Password = document.getElementById('password').value;
	var CurrPass = document.getElementById('CurrPassChange').value;
	if(CurrPass != Password)
	{		
		document.getElementById('Result_ChangePassword').style.color = "red";
		document.getElementById('Result_ChangePassword').innerHTML = "Mật khẩu hiện tại không đúng";
	}
	else
	{
		var NewPass = document.getElementById('NewPassChange').value;
		var ReNewPass = document.getElementById('ReNewPassChange').value;
		if(NewPass.length == 0)
		{
			document.getElementById('Result_ChangePassword').style.color = "red";
			document.getElementById('Result_ChangePassword').innerHTML = "Mật khẩu mới không được để trống";		
		}
		else if(NewPass.length < 6)
		{
			document.getElementById('Result_ChangePassword').style.color = "red";
			document.getElementById('Result_ChangePassword').innerHTML = "Mật khẩu phải có từ 6-20 ký tự";		
		}
		else if(NewPass!=ReNewPass)
		{
			document.getElementById('Result_ChangePassword').style.color = "red";
			document.getElementById('Result_ChangePassword').innerHTML = "Xác nhận mật khẩu không đúng";		
		}
		else
			return 1;
	}
}
function ChangePassword()
{
	var t = CheckPassword();
	if(t == 1)
		{
		var Username = document.getElementById('username').value;
		var Password = document.getElementById('NewPassChange').value;
		var xmlhttp;
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				if(xmlhttp.responseText=="1")
				{
					document.getElementById('Result_ChangePassword').style.color = "green";
					document.getElementById("Result_ChangePassword").innerHTML = "Cập nhật mật khẩu thành công";
					document.getElementById('password').value = document.getElementById('NewPassChange').value;
				}
			}
		}
		xmlhttp.open("GET","ChangePassword.php?Username="+Username+"&Password="+Password+"&t="+(new Date()).getTime(),true);
		xmlhttp.send();
	}
}
//
var layout = 0;
function mouseover_left(i)
{
	document.getElementsByClassName('button_left').item(i).style.backgroundColor = "#D5D5D5";
}
function mouseout_left(i)
{
	if(layout == 0)
		document.getElementsByClassName('button_left').item(i).style.backgroundColor = "#EAEAEA";
	else if(layout == 1)
		document.getElementsByClassName('button_left').item(i).style.backgroundColor = "#0099FF";
}
function showTrangChu()
{
	resetCenter();
	document.getElementById('GioiThieu').style.display = "block";
	document.getElementById('center').style.borderTop = "1px dashed #EFEFEF";
}
function changbg(a)
{
	var l = document.getElementsByClassName('button_menu').length;
	for(i = 0; i < l; ++i)
	{
	document.getElementsByClassName("button_menu").item(i).style.backgroundColor = "#F8F8F8";
	}
	document.getElementsByClassName("button_menu").item(a).style.backgroundColor = "#ABABAB";
}
function changeLayout(color)
{
	var l = document.getElementsByClassName('detailIcon').length;
	var l2 = document.getElementsByClassName('button_left').length;
	if(color == 0)
	{
		layout = 0;
		for(var j = 0; j < l2; j++)
			document.getElementsByClassName('button_left').item(j).style.backgroundColor = "#333333";		
		document.body.style.backgroundImage = "url(images/black/black.jpg)";
		document.getElementById('tr').style.background = "#333333";
		document.getElementById('tr').style.color = "#FFF";					
		for(var i = 0; i < l; ++i)
			document.getElementsByClassName('detailIcon').item(i).style.backgroundImage = "url(images/black/detail_black.jpg)";
	}
	else if(color == 1)
	{
		layout = 1;
		for(var j = 0; j < l2; j++)
			document.getElementsByClassName('button_left').item(j).style.backgroundColor = "#0099FF";				
		document.body.style.backgroundImage = "url(images/blue/blue2.jpg)";
		document.getElementById('tr').style.background = "#0099FF";
		document.getElementById('tr').style.color = "#FFF";				
		for(var i = 0; i < l; ++i)
			document.getElementsByClassName('detailIcon').item(i).style.backgroundImage = "url(images/blue/detail_blue.png)";
	}
}
function showSanPham(type,page,more)
{
	document.getElementById('center').style.borderTop = "0px";
	resetCenter();
	if(type==5)
		more = document.getElementById('SearchBox').value;
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			document.getElementById("data").innerHTML=xmlhttp.responseText;		
    	}
  	}
	xmlhttp.open("GET","sanpham.php?type="+type+"&page="+page+"&more="+more+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
function Search(page)
{
	resetCenter();
	var Keyword = document.getElementById('SearchBox').value;
	var SearchType = document.getElementById('selectSearch').value;
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			document.getElementById("data").innerHTML=xmlhttp.responseText;		
			if(layout == 0)
			{
				document.getElementById('tr').style.background = "#333333";
				document.getElementById('tr').style.color = "#FFF";					
			}
			else if(layout == 1)
			{
				document.getElementById('tr').style.background = "#0099FF";
				document.getElementById('tr').style.color = "#FFF";									
			}
    	}
  	}
	if(SearchType==0)
	xmlhttp.open("GET","sanpham.php?page="+page+"&type="+5+"&more="+Keyword+"&t="+(new Date()).getTime(),true);
	else
	if(SearchType==1)
	xmlhttp.open("GET","doanhnghiep.php?page="+page+"&type="+2+"&Keyword="+Keyword+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
function showRegForm()
{
	resetCenter();
	document.getElementById('regForm').style.display = "block";
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			document.getElementById("regForm").innerHTML=xmlhttp.responseText;
    	}
  	}
	xmlhttp.open("GET","RegForm.php?t="+(new Date()).getTime(),true);
	xmlhttp.send();
};
function showInfo(masanpham)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			document.getElementById("SanPhamInfo").innerHTML=xmlhttp.responseText;
    	}
  	}
	xmlhttp.open("GET","InfoSanPham.php?m="+masanpham+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
function resetLoginForm()
{
	document.getElementById('username').value="";
	document.getElementById('password').value="";
	document.getElementById('result_login').style.visibility = "none";;
}
function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
function login()
{
	resetCenter();
	if(document.getElementById('CheckboxRemember').checked)
	{
		setCookie("username",document.getElementById('username').value,5);
		setCookie("password",document.getElementById('password').value,5);
	}
	else
	{
		setCookie("username",document.getElementById('username').value,-5);
		setCookie("password",document.getElementById('password').value,-5);
	}
	
	
	var username, password;
	var xmlhttp;
	username = document.getElementById('username').value;
	password = document.getElementById('password').value;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			if(xmlhttp.responseText=="")
				document.getElementById('result_login').style.visibility = "visible";
			else
			{
				document.getElementById('LoginInfo').style.display = "none";
				document.getElementById('LoginResult').style.display = "block";
				document.getElementById('Member').innerHTML = xmlhttp.responseText+username;
				document.getElementById('wrapper').style.height = "1140px";
				document.getElementById('content').style.height = "940px";
				document.getElementById('left').style.height = "790px";
				document.getElementById('center').style.height = "890px";				
			}
    	}
  	}
	xmlhttp.open("GET","login.php?username="+username+"&password="+password+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
function SendPasswordForm()
{
	resetCenter();
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{		
			document.getElementById('SendPasswordForm').style.height = "200px";			
			document.getElementById('SendPasswordForm').style.display = "block";
			document.getElementById('SendPasswordForm').innerHTML = xmlhttp.responseText;
    	}
  	}
	xmlhttp.open("GET","SendPasswordForm.php?t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
function SendPassword()
{
	var username = document.getElementById('UsernameSendPassword').value;
	var email = document.getElementById('EmailSendPassword').value;	
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{			
			if(xmlhttp.responseText=="OK")
			{
				document.getElementById('SendPasswordForm').style.height = "100px";
				document.getElementById('UsernameSendPasswordBox').style.display = "none";
				document.getElementById('EmailSendPasswordBox').style.display = "none";
				document.getElementById('btnSendPassword').style.display = "none";
				document.getElementById('ResultSendPassword').style.display = "block";
				document.getElementById('ResultSendPassword').innerHTML = "Thông tin của bạn đã được gởi tới "+ email;
			}
    	}
  	}
	xmlhttp.open("GET","SendPassword.php?username="+username+"&email="+email+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
function logout()
{
	resetCenter();
	var username = getCookie('username');
	var password = getCookie('password');
	if(username == null || username == "")
	{
		document.getElementById('username').value = "";
		document.getElementById('password').value = "";
		document.getElementById('CheckboxRemember').checked = false;
	}
	document.getElementById('LoginInfo').style.display = "block";
	document.getElementById('LoginResult').style.display = "none";
	document.getElementById('quanly_admin').style.display = "none";
	document.getElementById('quanly_member').style.display = "none";
}
function CheckUsernameExist()
{
	var Username = document.getElementById('username-reg').value;
	if(Username.length ==0)
	{
		document.getElementById('result_reg_username').style.visibility = "visible";
		document.getElementById('result_reg_username').innerHTML = "Tên người dùng không được để trống";
		document.getElementById('result_reg_username').style.color = "red";
		return 0;
	}
	else
	if(Username.length < 6 || Username.length > 20)
	{
		document.getElementById('result_reg_username').style.visibility = "visible";
		document.getElementById('result_reg_username').innerHTML = "Tên người dùng phải có từ 6-20 ký tự";
		document.getElementById('result_reg_username').style.color = "red";
		return 0;
	}
	else
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				if(xmlhttp.responseText=="C")
				{
					document.getElementById('result_reg_username').style.visibility = "visible";
					document.getElementById('result_reg_username').innerHTML = "Tên đăng nhập này đã tồn tại";				
					document.getElementById('result_reg_username').style.color = "red";
					return 0;
				}
				else
				{
					document.getElementById('result_reg_username').style.visibility = "visible";
					document.getElementById('result_reg_username').innerHTML = "Tên đăng nhập này có thể dùng";
					document.getElementById('result_reg_username').style.color = "green";
				}
			}
		}
		xmlhttp.open("GET","CheckUsernameExist.php?Username="+Username+"&t="+(new Date()).getTime(),true);
		xmlhttp.send();
	}
}
function CheckPasswordReg()
{
	var Password = document.getElementById('password-reg').value;
	if(Password.length == 0)
	{
		document.getElementById('result_reg_pass').style.visibility = "visible";
		document.getElementById('result_reg_pass').innerHTML = "Mật khẩu không được để trống";
		document.getElementById('result_reg_pass').style.color = "red";
		return 0;
	}
	else
	if(Password.length < 6)
	{
		document.getElementById('result_reg_pass').style.visibility = "visible";
		document.getElementById('result_reg_pass').innerHTML = "Mật khẩu phải có ít nhất 6 ký tự";
		document.getElementById('result_reg_pass').style.color = "red";
		return 0;
	}
	else
	{
		document.getElementById('result_reg_pass').style.visibility = "visible";
		document.getElementById('result_reg_pass').innerHTML = "Mật khẩu có thể sử dụng";
		document.getElementById('result_reg_pass').style.color = "green";
	}
}
function CheckRePasswordReg()
{
	var Password = document.getElementById('password-reg').value;
	var RePassword = document.getElementById('repassword-reg').value;
	if(Password != RePassword)
	{
		document.getElementById('result_reg_repass').style.visibility = "visible";
		document.getElementById('result_reg_repass').innerHTML = "Xác nhận mật khẩu không đúng";
		document.getElementById('result_reg_repass').style.color = "red";
		return 0;
	}
	else
	{
		document.getElementById('result_reg_repass').style.visibility = "hidden";
	}
}
function CheckSoDienThoaiReg()
{
	var PhoneNumber = document.getElementById('sodienthoai-reg').value;
	if(PhoneNumber.length > 0)
	{
		var ch = PhoneNumber[PhoneNumber.length-1];
		if(ch=="0"||ch=="1"||ch=="2"||ch=="3"||ch=="4"||ch=="5"||ch=="6"||ch=="7"||ch=="8"||ch=="9"||ch==" "||ch==".")
		{
			document.getElementById('result_reg_phone').style.visibility = "hidden";
		}
		else
		{
			document.getElementById('result_reg_phone').style.visibility = "visible";
			document.getElementById('result_reg_phone').innerHTML = "Số điện thoại chỉ chứa số, dấu . và khoảng trắng";
			document.getElementById('result_reg_phone').style.color = "red";
			return 0;
		}
	}
	else
	{
		document.getElementById('result_reg_phone').style.visibility = "hidden";
	}
}
function CheckSoFaxReg()
{
	var FaxNumber = document.getElementById('Fax-reg').value;
	if(FaxNumber.length > 0)
	{
		var ch = FaxNumber[FaxNumber.length-1];
		if(ch=="0"||ch=="1"||ch=="2"||ch=="3"||ch=="4"||ch=="5"||ch=="6"||ch=="7"||ch=="8"||ch=="9"||ch==" "||ch==".")
		{
			document.getElementById('result_reg_fax').style.visibility = "hidden";
		}
		else
		{
			document.getElementById('result_reg_fax').style.visibility = "visible";
			document.getElementById('result_reg_fax').innerHTML = "Số fax chỉ chứa số, dấu . và khoảng trắng";
			document.getElementById('result_reg_fax').style.color = "red";
			return 0;
		}
	}
	else
	{
		document.getElementById('result_reg_fax').style.visibility = "hidden";
	}
}
function CheckTenDoanhNghiepReg()
{
	var TenDoanhNghiep = document.getElementById('tendoanhnghiep-reg').value;
	if(TenDoanhNghiep.length == 0)
	{
		document.getElementById('result_reg_tendoanhnghiep').style.visibility = "visible";
		document.getElementById('result_reg_tendoanhnghiep').innerHTML = "Tên doanh nghiệp không được để trống";
		document.getElementById('result_reg_tendoanhnghiep').style.color = "red";
		return 0;
	}
	else
	{
		document.getElementById('result_reg_tendoanhnghiep').style.visibility = "hidden";
	}
}
function Register()
{
	var a = CheckUsernameExist();
	var b = CheckPasswordReg();
	var c = CheckSoDienThoaiReg();
	var d = CheckSoFaxReg();
	var e = CheckTenDoanhNghiepReg();
	if(a!=0 && b!=0 && CheckRePasswordReg()!=0 && c!=0 && d!=0 && e!=0)
	{
		var username = document.getElementById('username-reg').value;
		var password = document.getElementById('password-reg').value;
		var repassword = document.getElementById('repassword-reg').value;
		var tendoanhnghiep = document.getElementById('tendoanhnghiep-reg').value;
		var nganh = document.getElementById('nganh-reg').value;
		var SoDienThoai = document.getElementById('sodienthoai-reg').value;
		var SoFax = document.getElementById('Fax-reg').value;
		var DiaChi = document.getElementById('DiaChi-reg').value;
		
		var xmlhttp;	
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				if(xmlhttp.responseText=="1")
				{
					document.getElementById('result_reg').style.color = "green";
					document.getElementById('result_reg').style.visibility = "visible";
					document.getElementById('result_reg').innerHTML = "Đăng ký tài khoản thành công";
				}
			}
		}
		xmlhttp.open("GET","register.php?username="+username+"&password="+password+"&tendoanhnghiep="+tendoanhnghiep+"&nganh="+nganh+"&SoDienThoai="+SoDienThoai+"&SoFax="+SoFax+"&DiaChi="+DiaChi+"&t="+(new Date()).getTime(),true);
		xmlhttp.send();
	}
}

function showFormDangKy()
{
	document.getElementById("center").style.visibility = 'visible';
}
function signup()
{
	var user, pass, repass;
	user = document.getElementById("username_signup").value;
	pass = document.getElementById("password_signup").value;
	repass = document.getElementById("repassword_signup").value;
	if(pass != repass)
		alert("Mật khẩu không giống nhau");
	else
	{
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				document.getElementById("center").innerHTML=xmlhttp.responseText;
			}
		}
		xmlhttp.open("GET","signup.php?username="+user+"&password="+pass+"&t="+(new Date()).getTime(),true);
		xmlhttp.send();
	}
}
//Doanh nghiệp
function showDoanhNghiep(page,type)
{
	document.getElementById('center').style.borderTop = "0px";
	resetCenter();
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			document.getElementById("data").innerHTML=xmlhttp.responseText;
			if(layout == 0)
			{
				document.getElementById('tr').style.background = "#333333";
				document.getElementById('tr').style.color = "#FFF";					
			}
			else if(layout == 1)
			{
				document.getElementById('tr').style.background = "#0099FF";
				document.getElementById('tr').style.color = "#FFF";									
			}
    	}
  	}
	xmlhttp.open("GET","DoanhNghiep.php?page="+page+"&type="+type+"&t="+(new Date()).getTime(),true);
	xmlhttp.send();
}
function NextReg()
{
	document.getElementById('username-reg-box').style.display = "none";
	document.getElementById('password-reg-box').style.display = "none";
	document.getElementById('repassword-reg-box').style.display = "none";
	document.getElementById('membername-reg-box').style.display = "none";		
	document.getElementById('branch-reg-box').style.display = "inline";
	document.getElementById('phone-reg-box').style.display = "block";
	document.getElementById('fax-reg-box').style.display = "block";
	document.getElementById('address-reg-box').style.display = "block";
	document.getElementById('btnReg-reg-box').style.display = "block";
	document.getElementById('btnNextBack-reg-box').style.cssFloat = "left";
	document.getElementById('btnNextBackReg').value = "Back";
	document.getElementById('btnNextBackReg').onclick = BackReg;	
}
function BackReg()
{
	document.getElementById('username-reg-box').style.display = "block";
	document.getElementById('password-reg-box').style.display = "block";
	document.getElementById('repassword-reg-box').style.display = "block";
	document.getElementById('membername-reg-box').style.display = "block";		
	document.getElementById('branch-reg-box').style.display = "none";
	document.getElementById('phone-reg-box').style.display = "none";
	document.getElementById('fax-reg-box').style.display = "none";
	document.getElementById('address-reg-box').style.display = "none";
	document.getElementById('btnReg-reg-box').style.display = "none";
	document.getElementById('btnNextBack-reg-box').style.cssFloat = "right";
	document.getElementById('btnNextBackReg').value = "Next";
	document.getElementById('btnNextBackReg').onclick = NextReg;	
}
function GoToPage(url)
{
	window.location.href = url;
}
function ThongTinCaNhan()
{
	var quyen = document.getElementById('quyen').value;
	if(quyen == 1)
		document.getElementById('quanly_admin').style.display = "block";
	else if(quyen == 0)
		document.getElementById('quanly_member').style.display = "block";
}
function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
  {
  alert("Welcome again " + username);
  }
else 
  {
  username=prompt("Please enter your name:","");
  if (username!=null && username!="")
    {
    setCookie("username",username,365);
    }
  }
}